
import { render } from 'less';
import Swiper from '../../lib/swiper/swiper-bundle.min'; 
// import { request } from '../../utils/request';
require('./home.less')
require('../../assets/css/index.less')
require('../../assets/fonts/iconfont.css')
require('../../lib/swiper/swiper-bundle.min.css')
const  request= require('../../utils/request')
const renderTabbar = require('../../utils/tabbar')
function $(arr) {
  return document.querySelector(arr)
}
window.onload=()=>{
  renderTabbar()
function getClockInfo(){
  request.get('/api/user/clockInInfo').then(res=>{
    let {errno,data}=res.data
    if(errno ===0){
        if(data.isClockIn){
          $('.nowcard').textContent='已打卡'
          $('.nowcard').classList='clock1'
        }else{
          $('.nowcard').textContent='今日打卡'
          $('.nowcard').classList='nowcard'
        }
    }
  })
}
getClockInfo()
function getuser(){
  request.get('/api/user/info').then(res=>{
    let {errno,data}=res.data
    if(errno===0){
      render(data)
    }
  })
}
function render(data){
  $('.day').textContent=data.ranking
  $('#clockDay').textContent=data.clockCount
  $('.munber').textContent=data.badges

}
getuser()
nowcard.addEventListener('click',()=>{
  request.post('/api/user/clockIn').then(res=>{
    let {errno,message}=res.data
    if(errno===0){
      getuser()
      getClockInfo()
    }else{
      alert(message)
    }
  })
})



  var mySwiper = new Swiper ('.swiper', {
    navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },
    loop: true, 
    autoplay: {
        delay: 2500,
        disableOnInteraction: false,
      },
    
    pagination: {
        el: ".swiper-pagination",
      },
    
  })  
  
}
  
  